﻿angular.module('resources.periodProxy', []);
angular.module('resources.periodProxy').factory('periodProxy', ['rresource', '$http', 'APPSETTING', function (rresource, $http, APPSETTING) {
    var factory = rresource('peroid');

    factory.peroidPaging = function (index, itemCount, filter, successcb, failedcb) {

        var itemspage = (index - 1) * itemCount;
        var filterStr = "$top=" + itemCount + "&$skip=" + itemspage + "&$orderby= PeriodEnd desc" + "&$count=true";
        return factory.odataQuery(filterStr, successcb, failedcb);
    };

    factory.hisAreaPeroidPaging = function (index, itemCount, successcb, failedcb) {

        var itemspage = (index - 1) * itemCount;
        var filterStr = "$top=" + itemCount + "&$skip=" + itemspage + "&$orderby= sortCode" + "&$count=true" + "&history=HisArea";
        return factory.odataQuery(filterStr, successcb, failedcb); 
    };

    factory.searchInfo = function (type, successcb, failedcb)
    {
        $http({
            url: APPSETTING['serverUrl'] + '/api/peroid?Type=' + type,
            method: 'GET'
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    }

    factory.addNewperoidByEndTime = function (strEndaDt, successcb, failedcb) {

        $http({
            url: APPSETTING['serverUrl'] + '/api/peroid',
            method: 'POST',
            data: strEndaDt
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    };

    factory.startSOA = function (type, successcb, failedcb) {

        $http({
            url: APPSETTING['serverUrl'] + '/api/peroid?Type=' + type,
            method: 'POST'//,
            //data: strEndaDt
        }).success(function (response) {
            successcb(response);
        }).error(function (ex) {
            failedcb(ex);
        });
    };

    return factory;
} ]);
